const multer  = require('multer')
const path = require('path');
// 自定义存储的路径和 文件名
const storage = multer.diskStorage({
  // 自定义存储的路径
  destination: function (req, file, cb) {
    cb(null, './public/uploads')
  },
  // 自定义上传文件名
  filename: function (req, file, cb) {
    // file就是上传文件信息
   
    const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
    cb(null, file.fieldname + '-' + uniqueSuffix+path.extname(file.originalname))
  }
})
const upload = multer({ storage: storage })

module.exports = upload;